/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.zhaocai.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.zhaocai.entity.ZcmToolVersion;
import com.zcm.modules.zhaocai.service.ZcmToolVersionService;

/**
 * 软件版本发布管理Controller
 * @author www
 * @version 2018-04-30
 */
@Controller
@RequestMapping(value = "${adminPath}/zhaocai/zcmToolVersion")
public class ZcmToolVersionController extends BaseController {

	@Autowired
	private ZcmToolVersionService zcmToolVersionService;
	
	@ModelAttribute
	public ZcmToolVersion get(@RequestParam(required=false) String id) {
		ZcmToolVersion entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = zcmToolVersionService.get(id);
		}
		if (entity == null){
			entity = new ZcmToolVersion();
		}
		return entity;
	}
	
	@RequiresPermissions("zhaocai:zcmToolVersion:view")
	@RequestMapping(value = {"list", ""})
	public String list(ZcmToolVersion zcmToolVersion, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ZcmToolVersion> page = zcmToolVersionService.findPage(new Page<ZcmToolVersion>(request, response), zcmToolVersion); 
		model.addAttribute("page", page);
		return "modules/zhaocai/zcmToolVersionList";
	}

	@RequiresPermissions("zhaocai:zcmToolVersion:view")
	@RequestMapping(value = "form")
	public String form(ZcmToolVersion zcmToolVersion, Model model) {
		model.addAttribute("zcmToolVersion", zcmToolVersion);
		return "modules/zhaocai/zcmToolVersionForm";
	}

	@RequiresPermissions("zhaocai:zcmToolVersion:edit")
	@RequestMapping(value = "save")
	public String save(ZcmToolVersion zcmToolVersion, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, zcmToolVersion)){
			return form(zcmToolVersion, model);
		}
		zcmToolVersionService.save(zcmToolVersion);
		addMessage(redirectAttributes, "保存版本成功");
		return "redirect:"+Global.getAdminPath()+"/zhaocai/zcmToolVersion/?repage";
	}
	
	@RequiresPermissions("zhaocai:zcmToolVersion:edit")
	@RequestMapping(value = "delete")
	public String delete(ZcmToolVersion zcmToolVersion, RedirectAttributes redirectAttributes) {
		zcmToolVersionService.delete(zcmToolVersion);
		addMessage(redirectAttributes, "删除版本成功");
		return "redirect:"+Global.getAdminPath()+"/zhaocai/zcmToolVersion/?repage";
	}

}